package com.selfdriving.activity;

import com.selfdriving.R;
import android.app.ActivityGroup;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.Window;
import android.widget.CompoundButton;
import android.widget.FrameLayout;
import android.widget.RadioButton;
import android.widget.CompoundButton.OnCheckedChangeListener;

public class HomePageActivity extends ActivityGroup implements OnCheckedChangeListener {
		private FrameLayout container = null;
		private Intent intent1;
		private Intent intent2;
		private Intent intent3;
		private Intent intent4;
		private Intent intent5;

		@Override
		protected void onCreate(Bundle savedInstanceState) {
			super.onCreate(savedInstanceState);
			requestWindowFeature(Window.FEATURE_NO_TITLE);
			setContentView(R.layout.homepage);
			intent1 = new Intent(HomePageActivity.this, SearchFeatureActivity.class);
			intent2 = new Intent(HomePageActivity.this, TravelTogetherActivity.class);
			intent3 = new Intent(HomePageActivity.this, HomeActivity.class);
			intent4 = new Intent(HomePageActivity.this, SearchFeatureActivity.class);
			intent5 = new Intent(HomePageActivity.this, PassPortActivity.class);
			init();
		}

		public void init() {
			container = (FrameLayout) findViewById(R.id.tabcontent);
			RadioButton btnModule1 = (RadioButton) findViewById(R.id.tab_item_1);
			btnModule1.setOnCheckedChangeListener(this);
			RadioButton btnModule2 = (RadioButton) findViewById(R.id.tab_item_2);
			btnModule2.setOnCheckedChangeListener(this);
			RadioButton btnModule3 = (RadioButton) findViewById(R.id.tab_item_3);
			btnModule3.setOnCheckedChangeListener(this);
			RadioButton btnModule4 = (RadioButton) findViewById(R.id.tab_item_4);
			btnModule4.setOnCheckedChangeListener(this);
			RadioButton btnModule5 = (RadioButton) findViewById(R.id.tab_item_5);
			btnModule5.setOnCheckedChangeListener(this);
			btnModule3.setChecked(true);
		}

		@Override
		public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
			if (isChecked) {
				container.removeAllViews();
				switch (buttonView.getId()) {
				case R.id.tab_item_1:
					container.addView(getLocalActivityManager().startActivity("1",
							intent1).getDecorView());
					break;
				case R.id.tab_item_2:
					container.addView(getLocalActivityManager().startActivity("2",
							intent2).getDecorView());
					break;
				case R.id.tab_item_3:
					container.addView(getLocalActivityManager().startActivity("3",
							intent3).getDecorView());
					break;
				case R.id.tab_item_4:
					container.addView(getLocalActivityManager().startActivity("4",
							intent4).getDecorView());
					break;
				case R.id.tab_item_5:
					container.addView(getLocalActivityManager().startActivity("5",
							intent5).getDecorView());
					break;
				default:
					break;
				}
			}
		}

		@Override
		public boolean dispatchKeyEvent(KeyEvent event) {
			if ((event.getAction() == KeyEvent.ACTION_DOWN)
					&& (event.getKeyCode() == KeyEvent.KEYCODE_BACK)) {
				
			}
			return super.dispatchKeyEvent(event);
		}

	}
